package main

import (
	"fmt"
	"strings"
	"time"
)

type Reader interface {
	read(rc chan string)
}

type Writer interface {
	write(wc chan string)
}

type ReadFromFile struct {
	path string
}

type WriteToInfluxDB struct {
	DbDsn string
}

type logProcess struct {
	rc     chan string
	wc     chan string
	reader Reader
	writer Writer
}

func main() {
	r := &ReadFromFile{
		path: "./access.log",
	}
	w := &WriteToInfluxDB{
		DbDsn: "username@password..",
	}
	log := &logProcess{
		rc:     make(chan string),
		wc:     make(chan string),
		reader: r,
		writer: w,
	}
	//1.读取log
	go log.reader.read(log.rc)
	//2.解析log
	go log.process()
	//3.写入数据
	go log.writer.write(log.wc)

	time.Sleep(time.Second * 1)

}

func (r *ReadFromFile) read(rc chan string) {
	line := "message"
	rc <- line
}

func (l *logProcess) process() {
	data := <-l.rc
	l.wc <- strings.ToUpper(data)
}

func (w *WriteToInfluxDB) write(wc chan string) {
	fmt.Println(<-wc)
}
